package com.example.wan_android.http.code

import com.example.wan_android.http.RetrofitClient
import com.example.wan_android.http.bean.ProjectContentsData

class ProjectCategoryContentRespository {
    suspend fun fetchProjectCategoryContent(
        index: Int,
        cid: Int
    ): Result<List<ProjectContentsData>> {
        try {
            val response = RetrofitClient.instance.getProjectContentData(index, cid)
            if (response.isSuccessful && response.body()?.errorCode == 0) {
                return Result.success(response.body()?.data?.datas ?: emptyList())
            } else {
                return Result.failure(Exception("Error: ${response.body()?.errorMsg}"))
            }
        } catch (e: Exception) {
            return Result.failure(e)
        }
    }
}